feat(java): resolve JAR license URLs to SPDX IDs (Bundle-License, pom <url>)#10948
Open
DmitriyLewen wants to merge 8 commits into
Open
feat(java): resolve JAR license URLs to SPDX IDs (Bundle-License, pom <url>)#10948DmitriyLewen wants to merge 8 commits into
DmitriyLewen wants to merge 8 commits into
Conversation
Build a reverse "license URL -> SPDX ID" index from the seeAlso field of the SPDX license list. The generator normalizes URLs, unwraps web.archive.org snapshots, and collapses only/or-later/+ families to their base. licenses.json now maps each license ID to its normalized URLs, and NormalizeLicenseURL / SPDXLicenseIDByURL are exposed for the parsers.
Fall back to <license><url> when <name> is empty, mapping the URL to its SPDX ID via the seeAlso index. Unresolved URLs are skipped.
Resolve the OSGi Bundle-License manifest header (unfolding wrapped continuation lines and parsing the ;link= form) and the pom.xml <license><url> fallback for JAR-embedded poms to SPDX IDs. Values that do not resolve are skipped so the packed LICENSE file is still classified; the manifest read is bounded with io.LimitReader. Priority: pom <name> -> pom <url> -> Bundle-License -> LICENSE file.
…m <url> List the OSGi Bundle-License manifest header and the pom.xml <license><url> fallback among the JAR license sources, and note that license URLs are resolved to SPDX IDs via the SPDX seeAlso references.
1825f7f to
07a36f2
Compare
Two comments were left over from earlier iterations: one referenced a generator guard that was later removed, another used a "collapse to base" example that no longer matches the "smallest referencing ID" logic. A few verbose comments are also trimmed.
Replace the sync.OnceValue over the parsed licenses.json with a plain parseLicenses helper, so the intermediate map is not kept resident for the whole process. The validation set and URL index are still built lazily and independently.
8de29aa to
59982d6
Compare
Trim entry values with a single strings.Trim (dropping the trimBundleLicenseValue helper), and fall back to Bundle-License only when no Jenkins Plugin-License-Name is present instead of concatenating both manifest sources.
Range with strings.SplitSeq, use strings.CutSuffix, and put the blank "embed" import in its own gci section.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Java packages often declare their license only as a URL — in the OSGi
Bundle-Licensemanifest header or in the pom.xml<license><url>— instead of a name or an SPDX ID.Until now such URLs were not usable, so these packages carried no license.
This PR builds a reverse "license URL → SPDX ID" index from the
seeAlsofield of the SPDX license list and uses it to resolve those URLs.SPDX index (
magefiles/spdx.go,pkg/licensing)seeAlsoand embeds a normalized URL → SPDX-ID map;licenses.jsonmaps each license ID to its normalized URLs and still doubles as the SPDX license ID list used for validation.licensing.NormalizeLicenseURLcanonicalizes a URL (scheme,www., trailing slash, document extension,opensource.org/licenses/vs/license/, case) and unwrapsweb.archive.orgsnapshots down to the embedded URL.+/-only/-or-latervariants of one family is kept for the lexicographically smallest of those license IDs (which is the bare base when it is present, e.g.GPL-2.0), so the choice is deterministic and always a license that actually lists the URL.expression.SPDXLicenseIDByURLperforms the lookup and expects an already-normalized URL, mirroringSPDXLicenseID.Java parsers
<license>has no<name>, fall back to its<url>resolved to an SPDX ID — for both the standalone pom parser and the pom.xml embedded in a JAR.Bundle-Licensemanifest header: unfold wrapped continuation lines (per the JAR File Specification /java.util.jar.Manifest), then for each comma-separated entry resolve its name as an SPDX ID and as a URL, and its;link=attribute as a URL; entries that resolve to neither (free text,<<EXTERNAL>>) are skipped.<name>→ pom<url>→Bundle-License→ packed LICENSE file.The
expression.SPDXLicenseIDByURLmapping is data-driven from SPDX upstream, so it needs no hand-maintained dictionary.Before / after
jackson-coredeclares its license only as a URL in the OSGiBundle-Licensemanifest header:Before — the URL is ignored, so no license is reported:
After — the URL is resolved to its SPDX ID:
Binary size
The embedded SPDX seeAlso data and the new code add ~81 KiB (+0.04%) to the release binary.
-ldflags="-s -w")mainRelated issues
Checklist